<template>
  <!-- 公司设置 -->
  <div class="setting">
    <el-card>
      <el-tabs>
        <el-tab-pane label="角色管理">
          <el-button
            type="primary"
            class="btn"
            @click="addData"
          >+新增角色</el-button>
          <el-table :data="tableList" height="340" stripe border>
            <el-table-column label="序号" type="index" width="80px">
              <template v-slot="{ $index }">
                {{ (page.page - 1) * page.pagesize + $index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="角色名" prop="name" />
            <el-table-column label="描述" prop="description" />
            <el-table-column label="操作" width="220px ">
              <template v-slot="{ row }">
                <el-tag>分配权限</el-tag>
                <el-tag @click="setData(row.id)">修改</el-tag>
                <el-tag @click="delData(row)">删除</el-tag>
                <!-- <el-button>分配权限</el-button>
                <el-button>修改</el-button>
                <el-button>删除</el-button> -->
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页组件 -->
          <div class="page">
            <el-pagination
              :current-page="page.page"
              :page-sizes="[1, 10, 100, 200, 300, 400]"
              :page-size="page.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page.total"
              @size-change="sizeChange"
              @current-change="currentChange"
            />
          </div>
        </el-tab-pane>
        <el-tab-pane label="公司信息" lazy>
          <component :is="'Info'" />
          <!-- <Info /> -->
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- dialog插件 -->
    <DialogCom
      ref="DialogCom"
      :table-list="tableList"
      @currentChange="currentChange"
    />
  </div>
</template>
<script>
import DialogCom from './components/dialogCom.vue'
// import Info from './components/info.vue'
import { sysRole, sysRoleDelete, sysRoleId } from '@/api/setting'
export default {
  name: 'Setting',
  components: {
    DialogCom,
    Info: () => import('./components/info.vue')
  },
  data() {
    return {
      page: {
        page: 1, //	是	1	页码
        pagesize: 10, //	是	10	每页条数
        total: null
      },
      tableList: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await sysRole(this.page)
      this.tableList = res.data.rows
      this.page.total = res.data.total
    },
    sizeChange(size) {
      this.page.pagesize = size
      this.page.page = 1
      this.getData()
    },
    currentChange(page) {
      this.page.page = page
      this.getData()
    },
    addData() {
      this.$refs.DialogCom.mode = 'add'
      this.$refs.DialogCom.isShow = true
    },
    delData(row) {
      this.$confirm('是否删除该角色', '温馨提示').then(async() => {
        await sysRoleDelete(row.id)
        this.$message.success('删除成功')
        this.currentChange(1)
      })
    },
    async setData(id) {
      this.$refs.DialogCom.mode = 'edit'
      const res = await sysRoleId(id)
      this.$refs.DialogCom.form = res.data
      this.$refs.DialogCom.isShow = true
    }
  }
}
</script>
<style lang="scss" scoped>
.setting {
  padding: 20px 30px;
  .btn {
    margin-bottom: 10px;
  }
  .page {
    margin: 0 auto;
    padding-top: 10px;
    text-align: center;
  }
  .el-tag {
    margin: 0 5px;
    cursor: pointer;
  }
}
</style>
